<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>评分细则</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
    <link th:href="@{/css/index.css}" rel="stylesheet"/>
    <link th:href="@{/css/tool.css}" rel="stylesheet"/>

    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
</head>
<style>
    td {
        text-align: center;
    }
</style>
<body>
<div class="layui-container" style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">评标注意</div>
                <div class="layui-card-body">
                    <button type="button" class="layui-btn" id="uploadScore">点击上传评分</button>
                </div>
            </div>
        </div>

        <div class="layui-col-lg12 layui-col-xs12 layui-col-sm12 layui-col-md12">
            <table id="scoring" lay-filter='editing'></table>
        </div>
    </div>
</div>

</body>
<script>
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var sumScore = new Number(0);

    layui.config({base: '/js/'}).extend({
        tableMerge: 'tableMerge'
    });

    layui.use(['table', 'jquery', 'layer', 'tableMerge'], function () {
        var table = layui.table,
            tableMerge = layui.tableMerge,
            $ = layui.jquery;

        table.render({
            elem: '#scoring',
            // url: '/score/scoreDetailInfo',
            totalRow: true,
            cols: [
                [
                    {field: 'xm', title: '项目', merge: true, align: 'center', totalRowText: '合计'},
                    {field: 'pj', title: '评价指标', align: 'center'},
                    {field: 'qz', title: '指标权重', align: 'center'},
                    {
                        field: 'pf',
                        title: '评分',
                        edit: 'text',
                        width: 80,
                        align: 'center',
                        event: 'pfEdit',
                        totalRow: true
                    }
                ]
            ],
            data: [
                {id: 1, xm: "价格部分（30分）", pj: "投标报价", qz: "30%", pf: null}
                , {id: 2, xm: "技术部分（50分）", pj: "设备技术性能及技术资料", qz: "30%", pf: null}
                , {id: 3, xm: "技术部分（50分）", pj: "设备相关证书及技术资料", qz: "20%", pf: null}
                , {id: 4, xm: "商务部分（20分）", pj: "售后服务", qz: "5%", pf: null}
                , {id: 5, xm: "商务部分（20分）", pj: "相关业绩", qz: "10%", pf: null}
                , {id: 6, xm: "商务部分（20分）", pj: "综合实力", qz: "5%", pf: null}
            ],
            done: function (res) {
                tableMerge.render(this)
            }
        })

        table.on('tool(editing)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"

            if (obj.event === 'pfEdit') {
                layui.$(this).find('input').on('input propertychange', function () {
                    this.value = this.value.replace(/[^\d]+/g, '')
                });
            }

            var score1 = $(".layui-table-body").find('tr[data-index="0"] td[data-field="pf"] .layui-table-cell').text(),
                score2 = $(".layui-table-body").find('tr[data-index="1"] td[data-field="pf"] .layui-table-cell').text(),
                score3 = $(".layui-table-body").find('tr[data-index="2"] td[data-field="pf"] .layui-table-cell').text(),
                score4 = $(".layui-table-body").find('tr[data-index="3"] td[data-field="pf"] .layui-table-cell').text(),
                score5 = $(".layui-table-body").find('tr[data-index="4"] td[data-field="pf"] .layui-table-cell').text(),
                score6 = $(".layui-table-body").find('tr[data-index="5"] td[data-field="pf"] .layui-table-cell').text()
            sumScore = (+score1) + (+score2) + (+score3) + (+score4) + (+score5) + (+score6);
            $(".layui-table-total").find('td[data-field="pf"] .layui-table-cell').text(sumScore)

        });

        console.log(parent.rowData.tbInfo.id);

        $("#uploadScore").on('click', function () {
            //parent.layui.$(".layui-table-body").find(scoreClass1).find('td[data-field="pf"] .layui-table-cell').text(sumScore)
            $.ajax({
                type: "post",
                url: "/score/insertScoreInfo",
                data: {
                    zbId: parent.rowData.zbInfo.id,
                    tbId: parent.rowData.tbInfo.id,
                    score: sumScore
                },
                success: function (res) {
                    if(res.code == 200){
                        parent.layer.close(index);
                        parent.location.reload()
                    }
                }
            })
        })

    });
</script>
</html>